package com.xy.p2p.dao.impl;

import java.util.List;
import java.util.Map;
import java.util.Set;

import com.xy.common.page.Pagination;
import com.xy.core.dao.impl.BaseDaoImpl;
import com.xy.p2p.dao.TmemberratesDao;
import com.xy.p2p.model.Tmemberrates;

public class TmemberratesDaoImpl extends BaseDaoImpl<Tmemberrates> implements TmemberratesDao {
	public TmemberratesDaoImpl() {
		super(Tmemberrates.class);
	}
   
   
	@Override
	public List<Tmemberrates> getTmemberrates(Map<String, Object> map) {
		Object[] values = map.values().toArray();
		List<Tmemberrates> localList = findByHql(getHql(map), values);
		return localList;
	}

	@Override
	public Pagination getTmemberratesByPage(Map<String, Object> map, int pageNo,
			int pageSize) {
		Object[] values = map.values().toArray();
		return findByPage(getHql(map), values, pageNo, pageSize);
	}

	private String getHql(Map<String, Object> map) {
		StringBuffer str = new StringBuffer("from Tmemberrates tt");
		if(map.size()>0)str.append(" where ");
		Set<String> set = map.keySet();
		StringBuffer where = new StringBuffer();
		for (String name : set) {
			if (where.length() > 0)
				where.append(" and  ");
			where.append("tt.").append(name).append("=?");
		}
		return str.append(where.toString()).toString();
	}   
}